package pers.kw.config.handler;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.NoHandlerFoundException;
import pers.kw.protocol.ExceptionResponse;

/**
 * 接口404，如何进行异常捕获呢，并且不能影响静态资源
 */
//@ControllerAdvice
public class GlobalExceptionHandler {

    // 处理其他异常的方法
    @ExceptionHandler(Exception.class)
    public ExceptionResponse handleException(Exception ex) {
        // 处理其他异常的逻辑
        return ExceptionResponse.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Internal Server Error");
    }

    // 处理NoHandlerFoundException的方法
    @ExceptionHandler(NoHandlerFoundException.class)
    public ExceptionResponse handleNoHandlerFoundException(NoHandlerFoundException ex) {
        // 处理NoHandlerFoundException的逻辑
        return ExceptionResponse.fail(HttpStatus.NOT_FOUND.value(), "Not Found");
    }
}
